//
//  TF1to16Drawing.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/13.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF1to16Drawing: TFwhiteboardDidTouched {

    //用于最终传给sdk 做画板
     @objc let view = TFTouchesVIew()
    //涂鸦工具
    @objc let whiteboardTools = TFWhiteboardTools()
    //音视频容器
    @objc let mediaContainerView = TFMediaContainerView()
    //桌面分享容器
    @objc let desktopContainerView = TFDesktopContainerView()
    //讲台的相关配置
    @objc let podiumConfiguration = TF1to16PodiumConfiguration()
    //未上讲台用的
    @objc var rtcDownFrame = CGRect(x: 0, y: 0, width: 0, height: 0)
    //已经上讲台用的
    @objc var rtcUpFrame = CGRect(x: 0, y: 0, width: 0, height: 0)
    @objc var tempFrame = CGRect(x: 0, y: 0, width: 0, height: 0)
    //定时倒计时
    @objc let timerView = TFTimerView()
    //抢答
    @objc let responderView = TFResponderView()
    //转盘
    @objc let turntableView = TFTurntableView()
    //TODO:抽奖
    @objc let below = TalkfunHitTestView()
    //双击
    @objc public var doubleTapActionBlock:touchesBeganBlock?
    //放大缩小按键
    @objc let isFullButton = UIButton()
    //未有画板的占位
    @objc let defaultDrawing1vN = UIImageView()
//    @objc let lottery = TFLotteryImageView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
    //获奖名单
    @objc let listOfWinners = TFListOfWinners()
   
    override init(frame: CGRect) {
        super.init(frame: frame)

        self.addSubview(self.view)

      self.defaultDrawing1vN.isHidden = true

      self.defaultDrawing1vN.image = UIImage.init(named: "HTLive.bundle/defaultDrawing1vN")
        self.addSubview(self.defaultDrawing1vN)
         
        //TODO:   画板工具条
   
        self.whiteboardTools.isHidden = true
        self.addSubview(self.whiteboardTools)
    
        //TODO:桌面分享容器
        self.desktopContainerView.isUserInteractionEnabled = false
        self.desktopContainerView.backgroundColor = UIColor.clear
        self.addSubview(self.desktopContainerView)
       
        self.isFullButton.backgroundColor = UIColor(red: 2/255.0, green: 11/255.0, blue: 20/255.0, alpha: 0.6)
        self.isFullButton.layer.cornerRadius = 4
        self.isFullButton.isHidden = true
        self.addSubview(self.isFullButton)
        self.isFullButton.setImage(UIImage.init(named: "HTLive.bundle/ppt_enlarge"), for: .normal)
        self.isFullButton.addTarget(self, action: #selector(self.isFullButtonClicck), for: .touchUpInside)
       
        //TODO:定时器(倒计时)
         self.timerView.isHidden = true
        self.addSubview(self.timerView)
        
         //抢答
          self.responderView.isHidden = true
        
          self.responderView.backgroundColor = UIColor(red: 33/255.0, green: 38/255.0, blue: 46/255.0, alpha: 0.9)
          self.responderView.layer.cornerRadius = 5
 
        self.addSubview(self.responderView)
       //  NSLog(@"go===================>");
        //转盘

       self.turntableView.isHidden = true
        self.addSubview(self.turntableView)
        
       self.podiumConfiguration.isHidden = true
        self.addSubview(self.podiumConfiguration)
       self.podiumConfiguration.onPodium.isHidden = true
        
        
        //TODO:抽奖

        self.addSubview(self.below)
      
//        self.lottery.image = UIImage.init(named: "HTLive.bundle/lottery1vN")
//        self.lottery.isHidden = true
//        self.below.addSubview(self.lottery)
        
        //TODO:中奖名单
        self.listOfWinners.isHidden = true
        self.listOfWinners.backgroundColor = UIColor.red
        self.below.addSubview(self.listOfWinners)
        self.listOfWinners.layer.cornerRadius = 10
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.view.frame = self.bounds
        self.below.frame = self.bounds
        
//        self.lottery.frame = CGRect(x: (self.below.frame.size.width - 235)/2, y: (self.below.frame.size.height - 111)/2, width: 235, height: 111)
      
        
        self.listOfWinners.frame = CGRect(x: (self.below.frame.size.width-250)/2, y: (self.below.frame.size.height-210)/2, width: 250, height: 210)
       
        
        if (self.bounds.size.width>0&&self.bounds.size.height>0) {
              self.whiteboardTools.frame = self.bounds;
             self.mediaContainerView.frame = self.bounds;
             self.desktopContainerView.frame = self.bounds;
            
            if ( self.isFullButton.frame.size.width==0) {
                   self.isFullButton.frame = CGRect(x: self.frame.size.width - 33 - 5, y: self.frame.size.height - 33 - 5, width: 33, height: 33)
              
               }
                
               
               self.timerView.frame = CGRect(x: (self.frame.size.width - 120)/2, y: (self.frame.size.height - 120)/2, width: 120, height: 120)
           
               
               self.responderView.frame = CGRect(x: (self.frame.size.width - 155)/2, y: (self.frame.size.height - 155)/2, width: 155, height: 155)
          
               
               self.turntableView.frame = CGRect(x: (self.frame.size.width - 155-12.5)/2, y: (self.frame.size.height - 155-12.5)/2, width: 155+12.5, height: 155+12.5)
          
               
                self.defaultDrawing1vN.frame = CGRect(x: (self.frame.size.width-144)/2, y: (self.frame.size.height-84.75)/2, width: 144, height: 84.75)
               
               
               self.podiumConfiguration.frame = CGRect(x: 10, y: 0, width: 44, height: self.frame.size.height)
          
        }
    }
    @objc func isFullButtonClicck(_ btn:UIButton)
    {
        if(btn.isSelected==false){
            btn.isSelected = true
          
        }else{
            btn.isSelected = false
            
           
        }
        if self.doubleTapActionBlock != nil {
            self.doubleTapActionBlock!()
        }
        
    }

}
